import { list } from '../../../../api/cardBill'

const util = require('../../../../utils/util.js')
const app = getApp()
Page({

  data: {
    pageNum: 1,
    pageSize: 10,
    detailedList: []
  },


  onPullDownRefresh() {
    wx.showNavigationBarLoading()
    this.data.pageNum = 1
    setTimeout(() => {
      wx.hideNavigationBarLoading()
      this.loadPoint()
      wx.stopPullDownRefresh()
    }, 1000);
  },

  onReachBottom() {
    this.data.pageNum += 1
    this.loadPoint()
  },

  formatDate2Time(val) {
    let date = new Date(val);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d + " " + h + ":" + m + ":" + s;
  },
  loadPoint() {
    if (this.data.pageNum == 1) {
      this.data.detailedList = []
    }
    list({
      type:2,
      pageSize: this.data.pageSize,
      pageNum: this.data.pageNum
    }).then(res => {
      res.data.data.forEach(item => {
        item.createDate = this.formatDate2Time(item.createDate)
        item.thumbnail = 'https://cdn.rzico.com/v4.0/wallet-consumption.png'
        this.data.detailedList.push(item)
      })
      this.setData({
        detailedList: this.data.detailedList
      })
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadPoint()
  
  },

  /**z
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
})